Set FD_CLOEXEC on the pidfile fd, so that tapdisk does not get it.
authorEwan Mellor <ewan@xensource.com>
Thu, 14 Dec 2006 10:31:31 +0000 (10:31 +0000)
committerEwan Mellor <ewan@xensource.com>
Thu, 14 Dec 2006 10:31:31 +0000 (10:31 +0000)
Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/blktap/drivers/blktapctrl.c

index b16ab516b5523ce0628316d29940688966589c02..f2022fcc9755d396488b4b868822ee6aae3b9897 100644 (file)
@@ -629,6 +629,7 @@ static void write_pidfile(long pid)
        char buf[100];
        int len;
        int fd;
+       int flags;
 
        fd = open(PIDFILE, O_RDWR | O_CREAT, 0600);
        if (fd == -1) {
@@ -640,6 +641,18 @@ static void write_pidfile(long pid)
        if (lockf(fd, F_TLOCK, 0) == -1)
                exit(0);
 
+       /* Set FD_CLOEXEC, so that tapdisk doesn't get this file
+          descriptor. */
+       if ((flags = fcntl(fd, F_GETFD)) == -1) {
+               DPRINTF("F_GETFD failed (%d)\n", errno);
+               exit(1);
+       }
+       flags |= FD_CLOEXEC;
+       if (fcntl(fd, F_SETFD, flags) == -1) {
+               DPRINTF("F_SETFD failed (%d)\n", errno);
+               exit(1);
+       }
+
        len = sprintf(buf, "%ld\n", pid);
        if (write(fd, buf, len) != len) {
                DPRINTF("Writing pid file failed (%d)\n", errno);